package com.crm.service.impl.csd.customerManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.csd.customerManager.*;
import com.crm.dao.mapper.customMapper.csd.CustomerMemberCardDetailCustomMapper;
import com.crm.model.entity.contactManager.ContactExchangeCode;
import com.crm.model.entity.contactManager.ContactExchangeCodeExample;
import com.crm.model.entity.csd.customerManager.*;
import com.crm.model.vo.csd.customerManager.CustomerMemberCardDetailVO;
import com.crm.model.vo.csd.customerManager.MemberCardDetailVO;
import com.crm.service.csd.customerManager.CustomerMemberCardDetailDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author baijian
 * @Date 2021/7/23 11:12
 * (客服部)-客户管理-会员卡详情
 */
@Service("csdCustomerMemberCardDetailDbServiceImpl")
public class CustomerMemberCardDetailDbServiceImpl implements CustomerMemberCardDetailDbService {

    @Autowired
    private CustomerMemberCardDetailCustomMapper customerMemberCardDetailCustomMapper;

    @Autowired
    private CustomerMemberCardDetailSwipingRecordMapper customerMemberCardDetailSwipingRecordMapper;

    @Autowired
    private CustomerMemberCardDetailVideoViewingRecordMapper customerMemberCardDetailVideoViewingRecordMapper;

    @Autowired
    private CustomerMemberCardDetailMapper customerMemberCardDetailMapper;

    @Autowired
    private CustomerMemberCardDetailPhoneAnsweringRecordMapper customerMemberCardDetailPhoneAnsweringRecordMapper;

    @Autowired
    private CustomerMemberCardDetailLivePurchaseRecordMapper customerMemberCardDetailLivePurchaseRecordMapper;

    @Autowired
    private CustomerMemberCardDetailDemandPurchaseRecordMapper customerMemberCardDetailDemandPurchaseRecordMapper;

    @Autowired
    private CustomerMemberCardDetailLiveSignatureAppointmentMapper customerMemberCardDetailLiveSignatureAppointmentMapper;

    /**
     * 会员卡详细信息
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public CustomerMemberCardDetailVO selectCustomerCardDetail(String customerProductDetailMemberCardId) {
        return customerMemberCardDetailCustomMapper.selectCustomerCardDetail(customerProductDetailMemberCardId);
    }

    /**
     * 新增刷卡记录
     * @param swiping 刷卡记录
     * @author  baijian
     * @return
     */
    @Override
    public Boolean addCustomerMemberCardDetailSwipingRecord(CustomerMemberCardDetailSwipingRecord swiping) {
        Boolean result = false;
        int num = customerMemberCardDetailSwipingRecordMapper.insertSelective(swiping);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 视频观看记录
     * @param video 视频
     * @author baijian
     * @return
     */
    @Override
    public Boolean addCustomerMemberCardDetailVideoViewingRecord(CustomerMemberCardDetailVideoViewingRecord video) {
        Boolean result = false;
        int num = customerMemberCardDetailVideoViewingRecordMapper.insertSelective(video);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     *会员卡服务明细
     * @param customerMemberCardDetail 会员卡服务明细
     * @author baijian
     */
    @Override
    public Boolean addCustomerMemberCardDetail(CustomerMemberCardDetail customerMemberCardDetail) {
        Boolean result = false;
        int num = customerMemberCardDetailMapper.insertSelective(customerMemberCardDetail);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 电话答疑拨打记录
     * @param phoneAnswering 电话答疑拨打
     * @author baijian
     */
    @Override
    public Boolean addCustomerMemberCardDetailPhoneAnsweringRecord(CustomerMemberCardDetailPhoneAnsweringRecord phoneAnswering) {
        Boolean result = false;
        int num = customerMemberCardDetailPhoneAnsweringRecordMapper.insertSelective(phoneAnswering);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 直播购买记录
     * @param zb 直播
     * @author baijian
     */
    @Override
    public Boolean addCustomerMemberCardDetailLivePurchaseRecord(CustomerMemberCardDetailLivePurchaseRecord zb) {
        Boolean result = false;
        int num = customerMemberCardDetailLivePurchaseRecordMapper.insertSelective(zb);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 点播购买记录
     * @param db 点播购买
     * @author baijian
     * @return
     */
    @Override
    public Boolean addCustomerMemberCardDetailDemandPurchaseRecord(CustomerMemberCardDetailDemandPurchaseRecord db) {
        Boolean result = false;
        int num = customerMemberCardDetailDemandPurchaseRecordMapper.insertSelective(db);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 直播报名预约
     * @param appointment 直播报名预约
     * @author baijian
     */
    @Override
    public Boolean addCustomerMemberCardDetailLiveSignatureAppointment(CustomerMemberCardDetailLiveSignatureAppointment appointment) {
        Boolean result = false;
        int num = customerMemberCardDetailLiveSignatureAppointmentMapper.insertSelective(appointment);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 会员卡明细修改
     * @param customerMemberCardDetail 会员卡明细
     * @author baijian
     */
    @Override
    public Boolean updateCustomerMemberCardDetail(CustomerMemberCardDetail customerMemberCardDetail) {
        Boolean result = false;
        int num = customerMemberCardDetailMapper.updateByPrimaryKeySelective(customerMemberCardDetail);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 通过会员卡id查询会员卡明细
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public CustomerMemberCardDetail selectCustomerMemberCardDetail(String customerProductDetailMemberCardId) {
        CustomerMemberCardDetailExample customerMemberCardDetailExample = new CustomerMemberCardDetailExample();
        customerMemberCardDetailExample.setOrderByClause("create_tm desc");
        CustomerMemberCardDetailExample.Criteria criteria = customerMemberCardDetailExample.createCriteria();
        criteria.andCustomerProductDetailMemberCardIdEqualTo(customerProductDetailMemberCardId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<CustomerMemberCardDetail> list = customerMemberCardDetailMapper.selectByExampleWithBLOBs(customerMemberCardDetailExample);
        if(list != null && list.size() > 0){
            return list.get(0);
        }else{
            return null;
        }
    }

    /**
     * 刷卡记录
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public List<CustomerMemberCardDetailSwipingRecord> selectCustomerMemberCardDetailSwipingRecord(String customerProductDetailMemberCardId) {
        CustomerMemberCardDetailSwipingRecordExample customerMemberCardDetailSwipingRecordExample = new CustomerMemberCardDetailSwipingRecordExample();
        customerMemberCardDetailSwipingRecordExample.setOrderByClause("create_tm desc");
        CustomerMemberCardDetailSwipingRecordExample.Criteria criteria = customerMemberCardDetailSwipingRecordExample.createCriteria();
        criteria.andCustomerProductDetailMemberCardIdEqualTo(customerProductDetailMemberCardId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<CustomerMemberCardDetailSwipingRecord> list = customerMemberCardDetailSwipingRecordMapper.selectByExample(customerMemberCardDetailSwipingRecordExample);
        return list;
    }

    /**
     * 视频观看记录
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public List<CustomerMemberCardDetailVideoViewingRecord> selectCustomerMemberCardDetailVideoViewingRecord(String customerProductDetailMemberCardId) {
        CustomerMemberCardDetailVideoViewingRecordExample customerMemberCardDetailVideoViewingRecordExample = new CustomerMemberCardDetailVideoViewingRecordExample();
        customerMemberCardDetailVideoViewingRecordExample.setOrderByClause("create_tm desc");
        CustomerMemberCardDetailVideoViewingRecordExample.Criteria criteria = customerMemberCardDetailVideoViewingRecordExample.createCriteria();
        criteria.andCustomerProductDetailMemberCardIdEqualTo(customerProductDetailMemberCardId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<CustomerMemberCardDetailVideoViewingRecord> list = customerMemberCardDetailVideoViewingRecordMapper.selectByExample(customerMemberCardDetailVideoViewingRecordExample);
        return list;
    }

    /**
     * 电话答疑拨打记录
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public List<CustomerMemberCardDetailPhoneAnsweringRecord> selectCustomerMemberCardDetailPhoneAnsweringRecord(String customerProductDetailMemberCardId) {
        CustomerMemberCardDetailPhoneAnsweringRecordExample customerMemberCardDetailPhoneAnsweringRecordExample = new CustomerMemberCardDetailPhoneAnsweringRecordExample();
        customerMemberCardDetailPhoneAnsweringRecordExample.setOrderByClause("create_tm desc");
        CustomerMemberCardDetailPhoneAnsweringRecordExample.Criteria criteria = customerMemberCardDetailPhoneAnsweringRecordExample.createCriteria();
        criteria.andCustomerProductDetailMemberCardIdEqualTo(customerProductDetailMemberCardId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<CustomerMemberCardDetailPhoneAnsweringRecord> list = customerMemberCardDetailPhoneAnsweringRecordMapper.selectByExample(customerMemberCardDetailPhoneAnsweringRecordExample);
        return list;
    }

    /**
     * 直播报名预约
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public List<CustomerMemberCardDetailLiveSignatureAppointment> selectCustomerMemberCardDetailLiveSignatureAppointment(String customerProductDetailMemberCardId) {
        CustomerMemberCardDetailLiveSignatureAppointmentExample customerMemberCardDetailLiveSignatureAppointmentExample = new CustomerMemberCardDetailLiveSignatureAppointmentExample();
        customerMemberCardDetailLiveSignatureAppointmentExample.setOrderByClause("create_tm desc");
        CustomerMemberCardDetailLiveSignatureAppointmentExample.Criteria criteria = customerMemberCardDetailLiveSignatureAppointmentExample.createCriteria();
        criteria.andCustomerProductDetailMemberCardIdEqualTo(customerProductDetailMemberCardId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<CustomerMemberCardDetailLiveSignatureAppointment> list = customerMemberCardDetailLiveSignatureAppointmentMapper.selectByExample(customerMemberCardDetailLiveSignatureAppointmentExample);
        return list;
    }

    /**
     * 直播购买记录
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public List<CustomerMemberCardDetailLivePurchaseRecord> selectCustomerMemberCardDetailLivePurchaseRecord(String customerProductDetailMemberCardId) {
        CustomerMemberCardDetailLivePurchaseRecordExample customerMemberCardDetailLivePurchaseRecordExample = new CustomerMemberCardDetailLivePurchaseRecordExample();
        customerMemberCardDetailLivePurchaseRecordExample.setOrderByClause("create_tm desc");
        CustomerMemberCardDetailLivePurchaseRecordExample.Criteria criteria = customerMemberCardDetailLivePurchaseRecordExample.createCriteria();
        criteria.andCustomerProductDetailMemberCardIdEqualTo(customerProductDetailMemberCardId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<CustomerMemberCardDetailLivePurchaseRecord> list = customerMemberCardDetailLivePurchaseRecordMapper.selectByExample(customerMemberCardDetailLivePurchaseRecordExample);
        return list;
    }

    /**
     * 点播购买记录
     * @param customerProductDetailMemberCardId 会员卡id
     * @author baijian
     * @return
     */
    @Override
    public List<CustomerMemberCardDetailDemandPurchaseRecord> selectCustomerMemberCardDetailDemandPurchaseRecord(String customerProductDetailMemberCardId) {
        CustomerMemberCardDetailDemandPurchaseRecordExample customerMemberCardDetailDemandPurchaseRecordExample = new CustomerMemberCardDetailDemandPurchaseRecordExample();
        customerMemberCardDetailDemandPurchaseRecordExample.setOrderByClause("create_tm desc");
        CustomerMemberCardDetailDemandPurchaseRecordExample.Criteria criteria = customerMemberCardDetailDemandPurchaseRecordExample.createCriteria();
        criteria.andCustomerProductDetailMemberCardIdEqualTo(customerProductDetailMemberCardId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<CustomerMemberCardDetailDemandPurchaseRecord> list = customerMemberCardDetailDemandPurchaseRecordMapper.selectByExample(customerMemberCardDetailDemandPurchaseRecordExample);
        return list;
    }

    /**
     * 修改刷卡记录
     * @param skjl 刷卡记录
     * @author baijian
     */
    @Override
    public Boolean updateCustomerMemberCardDetailSwipingRecord(CustomerMemberCardDetailSwipingRecord skjl) {
        Boolean result = false;
        int num = customerMemberCardDetailSwipingRecordMapper.updateByPrimaryKeySelective(skjl);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 修改视频观看记录
     * @param video 视频观看记录
     * @author baijian
     */
    @Override
    public Boolean updateCustomerMemberCardDetailVideoViewingRecord(CustomerMemberCardDetailVideoViewingRecord video) {
        Boolean result = false;
        int num = customerMemberCardDetailVideoViewingRecordMapper.updateByPrimaryKeySelective(video);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 修改电话答疑拨打记录
     * @param dhdybd 电话答疑拨打记录
     * @author baijian
     */
    @Override
    public Boolean updateCustomerMemberCardDetailPhoneAnsweringRecord(CustomerMemberCardDetailPhoneAnsweringRecord dhdybd) {
        Boolean result = false;
        int num = customerMemberCardDetailPhoneAnsweringRecordMapper.updateByPrimaryKeySelective(dhdybd);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 修改直播报名预约
     * @param zbbmyy 直播报名预约
     * @author baijian
     */
    @Override
    public Boolean updateCustomerMemberCardDetailLiveSignatureAppointment(CustomerMemberCardDetailLiveSignatureAppointment zbbmyy) {
        Boolean result = false;
        int num = customerMemberCardDetailLiveSignatureAppointmentMapper.updateByPrimaryKeySelective(zbbmyy);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 修改直播购买记录
     * @param zbgmjl 直播购买记录
     * @author baijian
     */
    @Override
    public Boolean updateCustomerMemberCardDetailLivePurchaseRecord(CustomerMemberCardDetailLivePurchaseRecord zbgmjl) {
        Boolean result = false;
        int num = customerMemberCardDetailLivePurchaseRecordMapper.updateByPrimaryKeySelective(zbgmjl);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 修改点播购买记录
     * @param dbgmjl 点播购买记录
     * @author baijian
     */
    @Override
    public Boolean updateCustomerMemberCardDetailDemandPurchaseRecord(CustomerMemberCardDetailDemandPurchaseRecord dbgmjl) {
        Boolean result = false;
        int num = customerMemberCardDetailDemandPurchaseRecordMapper.updateByPrimaryKeySelective(dbgmjl);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 查询会员卡明细
     * @param customerProductDetailMemberCardId 会员卡id
     * @return
     */
    @Override
    public MemberCardDetailVO selectMemberCardDetail(String customerProductDetailMemberCardId) {
        return customerMemberCardDetailCustomMapper.selectMemberCardDetail(customerProductDetailMemberCardId);
    }
}
